package com.github.postsanf.yinian.slider.library;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.github.postsanf.yinian.slider.library.SliderTypes.BaseSliderView;

import java.util.List;

/**
 * A slider adapter
 */
public class SliderAdapter2 extends PagerAdapter {

    private Context mContext;
    private List<ImageView> mImageContents;

    public SliderAdapter2(Context context, List<ImageView> mImageContents) {
        mContext = context;
        this.mImageContents = mImageContents;
    }

//    public <T extends BaseSliderView> void addSlider(T slider) {
//        slider.setOnImageLoadListener(this);
//        mImageContents.add(slider);
//        notifyDataSetChanged();
//    }
//
//    public BaseSliderView getSliderView(int position) {
//        if (position < 0 || position >= mImageContents.size()) {
//            return null;
//        } else {
//            return mImageContents.get(position);
//        }
//    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    public <T extends BaseSliderView> void removeSlider(T slider) {
        if (mImageContents.contains(slider)) {
            mImageContents.remove(slider);
            notifyDataSetChanged();
        }
    }

    public void removeSliderAt(int position) {
        if (mImageContents.size() > position) {
            mImageContents.remove(position);
            notifyDataSetChanged();
        }
    }

    public void removeAllSliders() {
        mImageContents.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mImageContents.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView v = mImageContents.get(position);
//        View v = b.getView();
        container.addView(v);
        return v;
    }


}
